//
//  setops.cpp
//  stl1
//
//  Created by XiongGuang on 16/9/11.
//  Copyright © 2016年 XiongGuang. All rights reserved.
//

#include <stdio.h>
#include <iostream>
#include <string>
#include <set>
#include <algorithm>
#include <iterator>

int main()
{
    using namespace std;
    const int N=6;
    string s1[N]={"buffoon","thinkers","for","heavey","can","for"};
    string s2[N]={"metal","any","food","elegant","deliver","for"};
    set<string>A(s1,s1+N);
    set<string>B(s2,s2+N);
    
    ostream_iterator<string,char> out(cout," ");
    cout<<"Set A : ";
    copy(A.begin(), A.end(), out);
    cout<<endl;
    cout<<"Set B: ";
    copy(B.begin(), B.end(), out);
    cout<<endl;
    cout<<"Union A and B: ";
    set_union(A.begin(), A.end(), B.begin(), B.end(), out);
    
    cout<<"Intersection of A and B: ";
    set_intersection(A.begin(), A.end(), B.begin(), B.end(), out);
    cout<<endl;
    
    cout<<"Difference of A and B: ";
    set_difference(A.begin(), A.end(), B.begin(), B.end(), out);
    cout<<endl;
    
    set<string> C ;
    cout<<"set C:\n";
    set_union(A.begin(), A.end(), B.begin(), B.end(),insert_iterator<set<string>>(C,C.begin()));
    copy(C.begin(),C.end(),out);
    cout<<endl;
    
    string s3("grungy");
    C.insert(s3);
    cout<<"Set c after insertion: \n";
    copy(C.begin(),C.end(),out);
    cout<<endl;
    
    cout<<"Showing a range: \n";
    copy(C.lower_bound("ghost"),C.upper_bound("upook"),out);
    cout<<endl;
    return 0;
}
